﻿using FitbitAPI;
using FitbitAPI.Models;
using FitbitAPIWrapperGameUP.WrapperLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FitbitAPIWrapperGameUP
{
    public class FitbitAuthenticator
    {
        private static Authenticator _authentication;

        private static Authenticator Authentication
        {
            get
            {
                if(_authentication == null)
                    _authentication = new Authenticator(ConsumerInfo.ConsumerKey, ConsumerInfo.ConsumerSecret, ConsumerInfo.RequestTokenUrl, ConsumerInfo.AccessTokenUrl, ConsumerInfo.AuthorizationUrl);
                return _authentication;
            }
        }

        public static string GetAuthToken()
        {
            return Authentication.GetAuthToken();
        }

        public static string GetAuthVerifier(string Username, string Password, string OAuth_Token)
        {
            return Authentication.GetAuthVerifier(Username, Password, OAuth_Token);
        }

        public static AuthCredentialFitbit ProcessApprovedAuthCallback(string TempAuthToken, string Verifier)
        {
            AuthCredential credentials = Authentication.ProcessApprovedAuthCallback(TempAuthToken, Verifier);

            return new AuthCredentialFitbit
            {
                AuthToken = credentials.AuthToken,
                AuthTokenSecret = credentials.AuthTokenSecret,
                UserId = credentials.UserId
            };
        }

    }
}
